package com.lizhi.yun.system.sfrobot.handler;

import com.lizhi.client.RestClientService;
import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.base.BaseHandler;
import com.lizhi.yun.base.common.RoleOrganUtils;
import com.lizhi.yun.db.dao.UppUserDao;
import com.lizhi.yun.db.pojo.UppUserPOJO;
import com.lizhi.yun.system.sfrobot.enums.RobotType;
import com.lizhi.yun.system.sfrobot.enums.SfrobotServiceEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @Author: lizhi
 * @Description:
 * @Date: create in 2020/11/13 14:45
 */
@Slf4j
@Service
public class SfrobotAppointmentTimeHandler extends BaseHandler {

    @Resource
    private UppUserDao uppUserDao;

    @Resource
    private RestClientService restClientService;

    public ListResponseResult doMain(Map<String, Object> map, HttpServletRequest request) {
        String userAcct = request.getHeader("userAcct");
        UppUserPOJO uppUserPOJO = uppUserDao.selectById(userAcct);
        /*判断医院*/
        map.put("hospitalIds", RoleOrganUtils.listOrganIds(uppUserPOJO.getOrganIds()));
        String robotType = map.get("robotType").toString();
        String result = null;
        if (RobotType.UpperLimb.getEnValue().equals(robotType)){
            result = restClientService.postStringToService(SfrobotServiceEnum.HBSF_UPPERLIMB_APPOINTMENT_TIME.getEnName(), SfrobotServiceEnum.HBSF_UPPERLIMB_APPOINTMENT_TIME.getEnValue(), SamJsonUtil.toJson(map));
        } else if (RobotType.LowerLimb.getEnValue().equals(robotType)){
            result = restClientService.postStringToService(SfrobotServiceEnum.HBSF_LOWERLIMB_APPOINTMENT_TIME.getEnName(), SfrobotServiceEnum.HBSF_LOWERLIMB_APPOINTMENT_TIME.getEnValue(), SamJsonUtil.toJson(map));
        }
        return SamJsonUtil.toObject(result, ListResponseResult.class);
    }
}
